import request from '@/utils/request'

interface ApiResponse<T = any> {
  code: number;
  msg: string;
  data: T;
}

interface PageResult<T> {
  records: T[];
  total: number;
  size: number;
  current: number;
  pages: number;
}

// Assuming MenuItem is defined elsewhere or will be passed as a generic type if needed
// For simplicity, using 'any' for MenuItem related types for now if it's not directly accessible here.
// Ideally, MenuItem would be imported from a shared types file.
interface MenuItem {
  id?: number;
  parentId?: number;
  name: string;
  path?: string;
  component?: string;
  perms?: string;
  type?: 'M' | 'C' | 'F';
  icon?: string;
  orderNum?: number;
  status?: number;
  children?: MenuItem[];
}

export function getMenuList(params?: any): Promise<ApiResponse<MenuItem[]>> {
  return request({
    url: '/api/menu/list',
    method: 'get',
    params
  })
}

export function getAllMenuList(params?: any): Promise<ApiResponse<MenuItem[]>> {
  return request({
    url: '/api/menu/all',
    method: 'get',
    params
  })
}

export function getMenuPage(params?: any): Promise<ApiResponse<PageResult<MenuItem>>> {
  return request({
    url: '/api/menu/page',
    method: 'get',
    params
  })
}

export function addMenu(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/menu',
    method: 'post',
    data
  })
}

export function updateMenu(data: any): Promise<ApiResponse<any>> {
  return request({
    url: '/api/menu',
    method: 'put',
    data
  })
}

export function deleteMenu(id: number): Promise<ApiResponse<any>> {
  return request({
    url: `/api/menu/${id}`,
    method: 'delete'
  })
} 